﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShuiJiaXX.aspx.cs" Inherits="Web.Pages.YongShui.JiChuXX.ShuiJiaXX" Theme="Default" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../JS/AddEditCancel.js"></script>
    <script src="../../../JS/jquery.js"></script>
    <script type="text/javascript">
        function keyEnter(index) {
            var controls = new Array();
            controls[0] = document.getElementById("txtShuiJiaNo_I");
            controls[1] = document.getElementById("txtYongShuiJia_I");
            controls[2] = document.getElementById("txtKaiShiRQ_I");
            controls[3] = document.getElementById("txtShiPiWH_I");
            controls[4] = document.getElementById("txtShuoMing_I");
            var key = event.keyCode;
            if (key == 13) {
                index = index + 1;
                if (index == controls.length) {
                    index = 0;
                }
                controls[index].focus();
            }
        }

        function search() {
            if (conBH.GetText() == "") {
                return;
            }
            ASPxCallback1.PerformCallback("search");
        }

        function display(op, id) {
            hdCollection.Set("ID", id);
            if (op == "add") {
                btnAdd.SetVisible(false);
                btnPrint.SetVisible(false);
                lblOperateTip.SetText("添加");
                txtShuiJiaNo.SetText("");
                txtShuiJiaNo.SetEnabled(true);
                txtYongShuiJia.SetText("");
                txtYongShuiJia.SetEnabled(true);
                txtKaiShiRQ.SetText("");
                txtKaiShiRQ.SetEnabled(true);
                txtShiPiWH.SetText("");
                txtShiPiWH.SetEnabled(true);
                txtShuoMing.SetText("");
                txtShuoMing.SetEnabled(true);
                listCover(true, "divList");
                //loadpanel1.Show();
                $("#GridViewContentTable").show();
                txtShuiJiaNo.Focus();
            }
            else if (op == "edit") {
                btnAdd.SetVisible(false);
                btnPrint.SetVisible(false);
                lblOperateTip.SetText("修改");
                txtShuiJiaNo.SetEnabled(false);
                txtYongShuiJia.SetEnabled(true);
                txtKaiShiRQ.SetEnabled(true);
                txtShiPiWH.SetEnabled(true);
                txtShuoMing.SetEnabled(true);
                //loadpanel1.Show();
                listCover(true,"divList");
                $("#GridViewContentTable").show();
                ASPxCallback1.PerformCallback("info");
                txtYongShuiJia.Focus();
            }
            else {
                $("#GridViewContentTable").hide();
                btnAdd.SetVisible(true);
                btnPrint.SetVisible(true);
                //loadpanel1.Hide();
                listCover(false, "divList");
            }
        }

        function del(id) {
            hdCollection.Set("ID", id);
            if (confirm("确认删除吗？")) {
                ASPxCallback1.PerformCallback("del");
            }
            else {
                hdCollection.Set("ID", -1);
            }
        }

        function save() {
            if (txtShuiJiaNo.GetText() == "") {
                alert("请输入水价编号！");
                txtShuiJiaNo.Focus();
                return;
            }
            if (txtYongShuiJia.GetText() == "") {
                alert("请输入用水价！");
                txtYongShuiJia.Focus();
                return;
            }
            if (txtKaiShiRQ.GetText() == "") {
                alert("请输入开始日期！");
                txtKaiShiRQ.Focus();
                return;
            }
            ASPxCallback1.PerformCallback("save");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            if (state != "0") {
                alert(arr[2]);
            }
            else {
                if (type == "search") {
                    gvList.SetFocusedRowIndex(arr[3]);
                    gvList.MakeRowVisible(arr[3]);
                }
                else if (type == "info") {
                    txtShuiJiaNo.SetText(arr[3]);
                    txtYongShuiJia.SetText(arr[4]);
                    txtKaiShiRQ.SetText(arr[5]);
                    txtShiPiWH.SetText(arr[6]);
                    txtShuoMing.SetText(arr[7]);
                }
                else if (type == "del") {
                    alert(arr[2]);
                    gvList.PerformCallback();
                }
                else if (type == "save") {
                    alert(arr[2]);
                    display("init", -1);
                    gvList.PerformCallback();
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1" align="center">
            水价信息
        </div>
        <div style="display: none;">
            <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
            <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
        </div>
        <asp:UpdatePanel runat="server" ID="UpdatePanel1">
            <ContentTemplate>
                <div align="center">
                    <div style="width: 80%;">
                        <table align="left">
                            <tr>
                                <td align="right">水价编号：</td>
                                <td>
                                    <dx:ASPxTextBox ID="txtConShuiJiaBH" ClientInstanceName="conBH" runat="server" Width="150px">
                                        <ClientSideEvents KeyPress="function(s,e){var key = event.keyCode;
                                        if( key==13){search();}}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td>
                                    <dx:ASPxButton ID="btnSearch" ClientInstanceName="btnSearch" runat="server" Text="查找" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){search();}">
                                    </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div align="center">                    
                    <div id="divList">
                        <dx:ASPxGridView ID="gvList" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1" Width="100%" Settings-HorizontalScrollBarMode="Auto" OnCustomCallback="gvList_CustomCallback">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_SHUIJIABH" Caption="水价编号" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="N_YSJ" Caption="用水价" Width="20%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="D_KAISHI" PropertiesTextEdit-DisplayFormatString="yyyy-MM-dd" Caption="开始日期" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_PIWENBH" Caption="市批文号" Width="20%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_SHUOMING" Caption="说明" Width="30%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Width="35px">
                                    <DataItemTemplate>
                                        <a href="#" onclick="display('edit','<%#Eval("ID")%>')">修改</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Width="35px">
                                    <DataItemTemplate>
                                        <a href="#" onclick="del('<%#Eval("ID")%>')">删除</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <Settings VerticalScrollableHeight="250" VerticalScrollBarMode="Auto" />
                            <ClientSideEvents Init="function(s,e){AdjustSize(300,gvList);}"  />
                        </dx:ASPxGridView>
                    </div>
                    <div style="height: 3px;"></div>
                    <div style="text-align: right">
                        <hr />
                        <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false" ClientSideEvents-Click="function(s,e){display('add',-1)}" UseSubmitBehavior="false">
                        </dx:ASPxButton>
                        <dx:ASPxButton ID="btnPrint" ClientInstanceName="btnPrint" runat="server" Text="打印" UseSubmitBehavior="false">
                        </dx:ASPxButton>
                    </div>
                    <div id="GridViewContentTable" style="display: none;">
                        <div class="tabletitle1" align="center">
                            <dx:ASPxLabel ID="lblOperateTip" runat="server" ClientInstanceName="lblOperateTip" Text="添加"></dx:ASPxLabel>
                        </div>
                        <table border="0" style="width: 100%; margin: auto;">
                            <tr>
                                <td rowspan="5"></td>
                                <td align="right" style="width: 25%">水价编号：
                                </td>
                                <td style="width: 30%">
                                    <dx:ASPxTextBox ID="txtShuiJiaNo" ClientInstanceName="txtShuiJiaNo" runat="server" Width="100%" MaxLength="15">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(0);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td style="width: 20%"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">用水价：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtYongShuiJia" ClientInstanceName="txtYongShuiJia" runat="server" Width="100%">
                                        <ClientSideEvents KeyUp="function(s,e){inputFloat(s);keyEnter(1);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">开始日期：
                                </td>
                                <td>
                                    <dx:ASPxDateEdit ID="txtKaiShiRQ" ClientInstanceName="txtKaiShiRQ" runat="server" Width="100%">
                                    </dx:ASPxDateEdit>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">市批文号：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtShiPiWH" ClientInstanceName="txtShiPiWH" runat="server" Width="100%" MaxLength="30">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(3);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right" valign="top">说明：
                                </td>
                                <td colspan="2">
                                    <dx:ASPxMemo ID="txtShuoMing" ClientInstanceName="txtShuoMing" runat="server" Width="100%" MaxLength="133">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(4);}" />
                                    </dx:ASPxMemo>
                                    </t>
                                <td></td>
                            </tr>
                        </table>
                        <table id="GridViewButtonTable" runat="server" style="width: 100%">
                            <tr>
                                <td style="text-align: right;">
                                    <hr />
                                    <dx:ASPxButton ID="ASPxButton1" runat="server" Text="保存" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){save();}">
                                    </dx:ASPxButton>
                                    <dx:ASPxButton ID="btnCancel" runat="server" Text="放弃" AutoPostBack="false" ClientSideEvents-Click="function(s,e){display('init',-1);}" UseSubmitBehavior="false">
                                    </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
